//-----------------------------------------------------------------------
// <copyright file="a_users2DAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_users2DAOBase
    {
        #region Common methods
        public virtual a_users2 Createa_users2FromReader(IDataReader reader)
        {
            a_users2 item = new a_users2();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("Userid"))) item.Userid = (string)reader["Userid"];
                if (!reader.IsDBNull(reader.GetOrdinal("Login_email"))) item.Login_email = (string)reader["Login_email"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_users2 methods
            
        public virtual void Createa_users2(a_users2 a_users2)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_users2_ins");
                
                database.AddInParameter(dbCommand, "@Userid", DbType.String, a_users2.Userid);
                database.AddInParameter(dbCommand, "@Login_email", DbType.String, a_users2.Login_email);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_users2 methods
        
        public virtual void Updatea_users2(a_users2 a_users2)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_users2_upd");            
                
                database.AddInParameter(dbCommand, "@Userid", DbType.String, a_users2.Userid);
                database.AddInParameter(dbCommand, "@Login_email", DbType.String, a_users2.Login_email);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_users2 methods
        public virtual void Deletea_users2(string userid)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_users2_del");
                
                database.AddInParameter(dbCommand, "@Userid", DbType.String, userid);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_users2 methods
        
        public virtual a_users2 Geta_users2(string userid)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_users2_sel");
                
                database.AddInParameter(dbCommand, "@Userid", DbType.String, userid);
                
                a_users2 a_users2 =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_users2 = Createa_users2FromReader(reader);
                        reader.Close();
                    }
                }
                return a_users2;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_users2List methods
        public virtual a_users2Collection Geta_users2List(a_users2Columns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_users2_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_users2Collection a_users2Collection = new a_users2Collection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_users2 a_users2 = Createa_users2FromReader(reader);
                        a_users2Collection.Add(a_users2);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_users2Collection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_users2Collection Geta_users2List(a_users2Columns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_users2List(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}